﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SecurityApi.Provider
{
    /// <summary>
    /// DO NOT USE THE DATA ACCESS OR BUSINESS LAYER CLASSES HERE. ALWAYS GO THROUGH THE SERVICE LAYER
    /// </summary>
    public class SoapSecurityManager
    {
        public List<SecurityApi.Model.Application> GetApplicationModules(string userName,int enterpriseId)
        {
            SecurityServiceReference.SecurityServiceClient proxy = new SecurityServiceReference.SecurityServiceClient();

            SecurityApi.Model.Application[] appArray = proxy.GetUserApplicationsByName(userName, enterpriseId);

            List<SecurityApi.Model.Application> appList = new List<SecurityApi.Model.Application>();
            foreach (var app in appArray)
            {
                appList.Add(app);
            }
            return appList;
        }

        public SecurityApi.Model.Application GetApplicationById(int moduleId)
        {
            SecurityServiceReference.SecurityServiceClient proxy = new SecurityServiceReference.SecurityServiceClient();
            return proxy.GetUserApplicationsById(moduleId);
        }


        public bool VerifyUser(string userName, string password, int enterpriseId = 1)
        {
            SecurityServiceReference.SecurityServiceClient proxy = new SecurityServiceReference.SecurityServiceClient();
            return proxy.VerifyUser(userName, password, enterpriseId);
        }

        public SecurityApi.Model.EnterpriseUser GetEnterpriseUser(string userName, int enterpriseId = 1)
        {
            SecurityServiceReference.SecurityServiceClient proxy = new SecurityServiceReference.SecurityServiceClient();
            SecurityApi.Model.EnterpriseUser result = proxy.GetEnterpriseUser(userName, enterpriseId);

            return result;
        }

        #region Private Implementation
        public void Dispose()
        {
        }
        #endregion


    }
}
